// code by onemen

// Look for RSS/Atom News Reader
function TMP_LookForRSS()
{
   if ("gotoLink" in window)
      TMP_wizzrss.init();

   if ("openNewsfox" in window)
      TMP_Newsfox.init();
}


// prevent Wizz RSS from load pages in locked tabs
var TMP_wizzrss =
{
   init : function ()
   {
      var codeToReplace = /getContentBrowser\(\).loadURI|contentBrowser.loadURI/;
      const newCode = "TMP_wizzrss.openURI";
      var _functions = ["addFeedbase","validate","gohome","tryagain","promptStuff","promptStuff",
                        "doSearch","viewLog","renderItem","playEnc","renderAllEnc","playAllEnc",
                        "gotoLink","gotoLink","itemLinkClick","itemLinkClick","itemListClick"];

      _functions.forEach(
         function(_function) {
            if (_function in window)
               eval("window." + _function + " ="+ window[_function].toString()
                  .replace(codeToReplace,newCode));
         }
      );
   },

   openURI : function (uri)
   {
      var w = Components.classes['@mozilla.org/appshell/window-mediator;1']
                                 .getService(Components.interfaces.nsIWindowMediator)
                                 .getMostRecentWindow("navigator:browser");
      var tabBrowser = w.getBrowser();

      var openNewTab = w.TMP_whereToOpen(true).lock;
      if (openNewTab) {
         var newTab = tabBrowser.addTab(uri);
         var theBGPref = !readPref("WizzRSSFocusTab", false, 2);
         tabBrowser.TMP_selectNewForegroundTab(newTab, theBGPref);
      }
      else
         tabBrowser.loadURI(uri);
   }
}

// prevent Newsfox from load pages in locked tabs
var TMP_Newsfox =
{
   init : function ()
   {
      eval("openNewsfox ="+openNewsfox.toString().replace(
         'if (newTab) {',
         'newTab = newTab || TMP_whereToOpen(null).lock; \ $&'
      ));
   }
}